﻿using System;
using UnityEngine;

namespace Assets.Scripts.Logic
{
    public class SubBtnParam
    {
        public Action<EnumExample, int> m_ClickAction;
        public string m_BtnName;
        public string m_Description;
        public EnumExample m_exampleType;
        public int m_btnIndex;

        public void Reset()
        {
            m_ClickAction = null;
            m_BtnName = string.Empty;
            m_Description = string.Empty;
            m_exampleType = EnumExample.invalid;
            m_btnIndex = 0;
        }
    }
    public class SubBtn:MonoBehaviour
    {
        public UIButton m_Btn;
        public UILabel m_BtnLabel;
        public UILabel m_DesLabel;

        private EnumExample _exampleType;
        private int _btnIndex;
        private Action<EnumExample, int> _clickAction;

        public void Init(SubBtnParam param)
        {
            m_BtnLabel.text = param.m_BtnName;
            m_DesLabel.text = param.m_Description;
            _clickAction = param.m_ClickAction;
            _exampleType = param.m_exampleType;
            _btnIndex = param.m_btnIndex;
            EventDelegate.Set(m_Btn.onClick, OnBtnClick);
        }

        private void OnBtnClick()
        {
            if (_clickAction != null)
            {
                _clickAction(_exampleType, _btnIndex);
            }
        }
    }
}